﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WorkOrder.Business;

namespace WorkOrder
{
    public partial class uinitTotal : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null || Session["UserID"].ToString() == "")
            {
                Session.Clear();
                ClientScript.RegisterClientScriptBlock(this.GetType(), "windowhref", "<script type='text/javascript'>alert('对不起，您还没有登录系统！');window.parent.location.href='../login.aspx';</script>");
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtSTART_DATE.Value.Trim() == "")
            {
                lblMsg.Text = "请输入开始时间！";
                return;
            }
            if (txtEND_DATE.Value.Trim() == "")
            {
                lblMsg.Text = "请输入结束时间！";
                return;
            }
            UnitTotal unit = new UnitTotal();
            string tmp = "";
            switch (seleUnit.Value)
            {
                case "1":
                    tmp = "Table_Integrated_unit";
                    break;
                case "2":
                    tmp = "Table_Debugging_unit";
                    break;
                case "3":
                    tmp = "Table_Supervision_unit";
                    break;
            }
            if (tmp != "")
                grv2.DataSource = grv1.DataSource = unit.getUnit(tmp);
            grv1.DataBind();
            grv2.DataBind();

            System.Data.DataTable tab1,tab2,tab3,tab4,tab5,tab6,tab7;

            #region 语音
            tab1 = unit.getPlan(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "1");
            tab2 = unit.getTry(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "1");
            tab3 = unit.getDebug(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "1");
            tab4 = unit.getTest(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "1");
            tab5 = unit.getDelivery(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "1");
            tab6 = unit.getReturnVisit(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "1");
            tab7 = unit.getPlanAndTry(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "1");
            for (int i = 0; i < grv1.Rows.Count; i++)
            {
                #region 先将所有单元格填0
                //grv1.Rows[i].Cells[1].Text = "0";
                //grv1.Rows[i].Cells[2].Text = "0";
                //grv1.Rows[i].Cells[3].Text = "0";
                //grv1.Rows[i].Cells[4].Text = "0";
                //grv1.Rows[i].Cells[5].Text = "0";
                //grv1.Rows[i].Cells[6].Text = "0";
                //grv1.Rows[i].Cells[7].Text = "0";
                #endregion

                for (int j = 0; j < tab1.Rows.Count; j++)
                    if (grv1.Rows[i].Cells[0].Text == tab1.Rows[j][0].ToString())
                        grv1.Rows[i].Cells[1].Text = tab1.Rows[j][1].ToString();

                for (int j = 0; j < tab2.Rows.Count; j++)
                    if (grv1.Rows[i].Cells[0].Text == tab2.Rows[j][0].ToString())
                        grv1.Rows[i].Cells[2].Text = tab2.Rows[j][1].ToString();

                for (int j = 0; j < tab3.Rows.Count; j++)
                    if (grv1.Rows[i].Cells[0].Text == tab3.Rows[j][0].ToString())
                        grv1.Rows[i].Cells[3].Text = tab3.Rows[j][1].ToString();

                for (int j = 0; j < tab4.Rows.Count; j++)
                    if (grv1.Rows[i].Cells[0].Text == tab4.Rows[j][0].ToString())
                        grv1.Rows[i].Cells[4].Text = tab4.Rows[j][1].ToString();

                for (int j = 0; j < tab5.Rows.Count; j++)
                    if (grv1.Rows[i].Cells[0].Text == tab5.Rows[j][0].ToString())
                        grv1.Rows[i].Cells[5].Text = tab5.Rows[j][1].ToString();

                for (int j = 0; j < tab6.Rows.Count; j++)
                    if (grv1.Rows[i].Cells[0].Text == tab6.Rows[j][0].ToString())
                        grv1.Rows[i].Cells[6].Text = tab6.Rows[j][1].ToString();

                for (int j = 0; j < tab7.Rows.Count; j++)
                    if (grv1.Rows[i].Cells[0].Text == tab7.Rows[j][0].ToString())
                        grv1.Rows[i].Cells[7].Text = tab7.Rows[j][1].ToString();
            }
            #endregion

            #region 数据
            tab1 = unit.getPlan(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "2");
            tab2 = unit.getTry(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "2");
            tab3 = unit.getDebug(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "2");
            tab4 = unit.getTest(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "2");
            tab5 = unit.getDelivery(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "2");
            tab6 = unit.getReturnVisit(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "2");
            tab7 = unit.getPlanAndTry(tmp, txtSTART_DATE.Value, txtEND_DATE.Value, "2");
            for (int i = 0; i < grv2.Rows.Count; i++)
            {
                #region 先将所有单元格填0
                //grv2.Rows[i].Cells[1].Text = "0";
                //grv2.Rows[i].Cells[2].Text = "0";
                //grv2.Rows[i].Cells[3].Text = "0";
                //grv2.Rows[i].Cells[4].Text = "0";
                //grv2.Rows[i].Cells[5].Text = "0";
                //grv2.Rows[i].Cells[6].Text = "0";
                //grv2.Rows[i].Cells[7].Text = "0";
                #endregion

                for (int j = 0; j < tab1.Rows.Count; j++)
                    if (grv2.Rows[i].Cells[0].Text == tab1.Rows[j][0].ToString())
                        grv2.Rows[i].Cells[1].Text = tab1.Rows[j][1].ToString();

                for (int j = 0; j < tab2.Rows.Count; j++)
                    if (grv2.Rows[i].Cells[0].Text == tab2.Rows[j][0].ToString())
                        grv2.Rows[i].Cells[2].Text = tab2.Rows[j][1].ToString();

                for (int j = 0; j < tab3.Rows.Count; j++)
                    if (grv2.Rows[i].Cells[0].Text == tab3.Rows[j][0].ToString())
                        grv2.Rows[i].Cells[3].Text = tab3.Rows[j][1].ToString();

                for (int j = 0; j < tab4.Rows.Count; j++)
                    if (grv2.Rows[i].Cells[0].Text == tab4.Rows[j][0].ToString())
                        grv2.Rows[i].Cells[4].Text = tab4.Rows[j][1].ToString();

                for (int j = 0; j < tab5.Rows.Count; j++)
                    if (grv2.Rows[i].Cells[0].Text == tab5.Rows[j][0].ToString())
                        grv2.Rows[i].Cells[5].Text = tab5.Rows[j][1].ToString();

                for (int j = 0; j < tab6.Rows.Count; j++)
                    if (grv2.Rows[i].Cells[0].Text == tab6.Rows[j][0].ToString())
                        grv2.Rows[i].Cells[6].Text = tab6.Rows[j][1].ToString();

                for (int j = 0; j < tab7.Rows.Count; j++)
                    if (grv2.Rows[i].Cells[0].Text == tab7.Rows[j][0].ToString())
                        grv2.Rows[i].Cells[7].Text = tab7.Rows[j][1].ToString();
            }
            #endregion 

            lblMsg.Text = "";
            tab1.Dispose();
            tab2.Dispose();
            tab3.Dispose();
            tab4.Dispose();
            tab5.Dispose();
            tab6.Dispose();
            tab7.Dispose();
        }

        protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex >= 0)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor,this.style.background='#ffe3a0'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#fff'");
            }
        } 
    }
}
